package mybatisgen.demo.service;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.api.ProgressCallback;
import org.mybatis.generator.api.VerboseProgressCallback;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: com.xinmei.mybatisgenGeneratorTool
 * @Description: mybatis gen tool
 * @author gdw
 * @date 2017年3月23日 下午2:16:28
 *
 */
public class GeneratorTool {
	public static void main(String[] args) throws Exception {




		List<String> warnings = new ArrayList<>();
		boolean overwrite = true;
		DefaultShellCallback callback = new DefaultShellCallback(overwrite);
		Configuration config = new ConfigurationParser(warnings).
				parseConfiguration(GeneratorTool.class.getClassLoader().
						getResourceAsStream("generatorConfig-sita.xml"));
		MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
				callback, warnings);
		ProgressCallback progressCallback = new VerboseProgressCallback();
		myBatisGenerator.generate(progressCallback);

		for (String warning : warnings) {
			System.out.println(warning);
		}

	}

	public static void extracted(InputStream inputStream) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
		List<String> warnings = new ArrayList<>();
		boolean overwrite = true;
		DefaultShellCallback callback = new DefaultShellCallback(overwrite);
		Configuration config = new ConfigurationParser(warnings).
				parseConfiguration(inputStream);

		MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
                callback, warnings);
		ProgressCallback progressCallback = new VerboseProgressCallback();
		myBatisGenerator.generate(progressCallback);

		for (String warning : warnings) {
            System.out.println(warning);
        }
	}


}
